package com.zpark.controller;

import com.zpark.mapper.IPersonMapper;
import com.zpark.pojo.Person;
import com.zpark.service.IPersonService;
import com.zpark.utils.HttpStatusAndMessage;
import com.zpark.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: PersonController
 * @Description:
 * @author: RZS
 * @date: 2024/3/18  8:48
 */
@RestController
@RequestMapping("/person")
@CrossOrigin  // 解决跨域问题
public class PersonController {

    @Autowired
    private IPersonService personService;

    // 查询所有用户数据
    @RequestMapping("/get_all")
    public JsonUtil<List<Person>> findAll(){
        return new JsonUtil<>(HttpStatusAndMessage.SUCCESS,
                HttpStatusAndMessage.SUCCESS_MSG, personService.findAll());

    }

    @PostMapping("/get_per/{uname}")
    public JsonUtil<Person> findByUsername(@PathVariable String uname){
        return new JsonUtil<>(HttpStatusAndMessage.SUCCESS,
                HttpStatusAndMessage.SUCCESS_MSG, personService.findByUsername(uname));

    }

    @RequestMapping("/del/{id}")
    public JsonUtil<Void> removeById(@PathVariable Integer id){
        // 调用业务层方法删除用户数据
        personService.removeById(id);

        return new JsonUtil<>(HttpStatusAndMessage.SUCCESS,
                HttpStatusAndMessage.SUCCESS_MSG, null);
    }

    @PostMapping("/change")
    public JsonUtil<Void> changePerson(@RequestBody Person person){

        return null;
    }

}
